package com.hzzy.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Util {
	private String md5_32;
	private String md5_16;
	private String md5_24;
	private byte[] b_32;
	
	public MD5Util(String sourceStr){
		String result = "";
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(sourceStr.getBytes());
			byte b[] = md.digest();
			b_32 = b;
			int i;
			StringBuffer buf = new StringBuffer("");
			for (int offset = 0; offset < b.length; offset++) {
			i = b[offset];
			if (i < 0)
				i += 256;
			if (i < 16)
				buf.append("0");
			buf.append(Integer.toHexString(i));
	 }
		result = buf.toString();
		md5_32=result;
		md5_16= buf.toString().substring(8, 24);
		md5_24 = buf.toString().substring(0, 24);
	 } catch (NoSuchAlgorithmException e) {
		 System.out.println(e);
	 }
	}
	 public String get16(){
	 return md5_16;
	 }
	 public String get32(){
	 return md5_32;
	 }
	 
	 public String get24() {
		 return md5_24;
	 }
	 public byte[] getB_32() {
		 return b_32;
	 }
}
